package com.smart.sms.listener;

import com.smart.common.constants.MessageConstants;
import com.smart.common.dto.member.MemberMsgDto;
import com.smart.sms.service.AliSmsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author zhangwei
 */
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = MessageConstants.MQ_SMS_GROUP, topic = MessageConstants.MQ_MEMBER_TOPIC)
public class SmsListener implements RocketMQListener<MemberMsgDto> {
    @Resource
    AliSmsService smsService;

    @Override
    public void onMessage(MemberMsgDto message) {
        if (message != null && message.getCode() != null && message.getPhone() != null) {
            smsService.sendCode(message.getPhone(), message.getCode());
        }
    }
}
